import React,{ FormEvent } from 'react'

// 无状态组件
const MyForm = ()=>{
    let userRef: React.RefObject<HTMLInputElement> = React.createRef()
    let pwdInput: HTMLInputElement | null;

    let handleSubmit = (e: FormEvent)=>{
        e.preventDefault();
        console.log('submit');
        // 取value的三种方式
        // console.log(userRef.current?.value);
        // console.log(userRef.current!.value);
        console.log((userRef.current as HTMLInputElement).value);

        console.log(pwdInput!.value)
    }

    return (
        <form onSubmit={handleSubmit}>
            username：<input type="text" ref={userRef} />
            password：<input ref={(node)=>pwdInput=node} />
            <button type="submit">提交</button>
        </form>
    )
}
export default MyForm;   
